package learn.advance.list1;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

class Demo1List{
    public static void Test(){
        List<String> list=new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");
        list.add("d");
        list.add("e");
        list.add("f");

        System.out.println(list);

        String r=list.remove(2);
        System.out.println(r);

        String old=list.set(0,"A");
        System.out.println(list);

        System.out.println("=========================");
        Iterator<String> it=list.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }

        System.out.println("=========================");
        for(String s:list){
            System.out.println(s);
        }

        System.out.println("=========================");
        String g=list.get(3);
        System.out.println(g);

    }
}

class Demo2LinkedList{
    public static void Test(){

        //Show1();
        //Show2();
        Show3();
    }

    private static void Show1(){
        LinkedList<String> linked=new LinkedList<>();
        linked.add("a");
        linked.add("b");
        linked.add("c");
        linked.add("d");

        System.out.println(linked.get(0));
        System.out.println(linked);
        String f=linked.pop();
        System.out.println("first:"+ f);
        String l=linked.removeFirst();
        System.out.println("last:"+ l);
        System.out.println(linked);
    }

    public static void Show2(){
        LinkedList<String> l=new LinkedList<>();
        l.add("a");
        l.add("b");
        l.add("c");
        String f=l.getFirst();
        System.out.println(f);
        String last=l.getLast();
        System.out.println(last);
        System.out.println(l);
    }

    public static void Show3(){
        LinkedList<String> l=new LinkedList<>();
        l.add("a");
        l.add("b");
        l.add("c");

        System.out.println(l);
        l.push("wwww");
        System.out.println(l);

        l.addLast("tttt");
        System.out.println(l);
    }
}







public class TestList {
    public static void main(String[] args) {
       // Demo1List.Test();
        Demo2LinkedList.Test();
    }
}
